package cn.goktech.oss.util;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
    读取配置文件中配置的所需基本数据
    @Value("${}")--读取配置文件中的配置项
    @PropertySource --引入需要读取的配置文件
 */
@PropertySource("classpath:application.properties")
@Component
public class BaseUtil implements InitializingBean {
    @Value("${aliyun.oss.file.endpoint}")
    private String endpoint;

    @Value("${aliyun.oss.file.keyid}")
    private String keyid;

    @Value("${aliyun.oss.file.keysecret}")
    private String keysecret;

    @Value("${aliyun.oss.file.bucketname}")
    private String bucketname;

    @Value("${test}")
    private String avatarFile;


    public static String END_POINT;
    public static String KEY_ID;
    public static String KEY_SECRET;
    public static String BUCKET_NAME;
    public static String AVATAR_DIR;

    //读取完配置文件属性并设置值后的操作
    //完成静态变量的赋值，便于访问
    @Override
    public void afterPropertiesSet() throws Exception {
        END_POINT = this.endpoint;
        KEY_ID = this.keyid;
        KEY_SECRET = this.keysecret;
        BUCKET_NAME = this.bucketname;
        AVATAR_DIR = this.avatarFile;
    }
}
